# coding=utf-8

from selenium.webdriver.common.by import By
from PageObject.base_page import BasePage
from PageObject.contact_page import ContactPage


class AddMemberPage(BasePage):
    """
    企业微信“添加成员”页面PO类
    """
    # 添加成员页面URL
    _base_url = "https://work.weixin.qq.com/wework_admin/frame#contacts"

    # 元素定位
    _username_selector = (By.CSS_SELECTOR, "#username")
    _acct_id_selector = (By.CSS_SELECTOR, "#memberAdd_acctid")
    _phone_number_selector = (By.CSS_SELECTOR, "#memberAdd_phone")
    _save_selector = (By.CSS_SELECTOR, ".js_btn_save")

    def add_member(self, username, acct_id, phone):
        """添加成员操作
        :param username: 成员姓名
        :param acct_id: 成员账号
        :param phone: 成员手机号码
        :return: 返回一个ContactPage实例
        """
        self.find(self._username_selector).send_keys(username)
        self.find(self._acct_id_selector).send_keys(acct_id)
        self.find(self._phone_number_selector).send_keys(phone)
        self.find(self._save_selector).click()

        return ContactPage(self.driver)

